package com.apes.framework.plugin.esb.api;


import com.apes.framework.api.SpringManager;
import com.apes.framework.plugin.filereader.xml.*;
import com.apes.framework.util.Tools;
import com.apes.oap.*;
import com.apes.oap.annotation.HttpAction;
import com.apes.oap.event.AfterStartedRopEvent;
import com.apes.oap.event.RopEventListener;
import com.apes.oap.response.OapResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * 功能：EsbEvent RopListener
 *
 * @author xul
 * @create 2017-12-05 14:05
 */
@Component
public class EsbEventListener implements RopEventListener<AfterStartedRopEvent> {
    protected final Logger logger = LogManager.getLogger(EsbEventListener.class);

    public void onRopEvent(AfterStartedRopEvent ropRopEvent) {
        RopContext ropContext = ropRopEvent.getRopContext();

       /*
        * 注册 ApesNodeParser
        */
        setApesNodeParser(ropContext.getApplicationContext());

       /*
        * 注册ApesElementParser
        */
        setApesElementParser(ropContext.getApplicationContext());

        SpringManager.getBean(XmlFileReader.class).init();
    }

    /*
     * 注册 ApesNodeParser
     */
    private void setApesNodeParser(ApplicationContext context) {
        context.getBeansOfType(ApesNodeParser.class).forEach((k, v) -> {
            ApesXmlParser.setApesNodeParser(v);
        });
    }

    /*
     * 注册 ApesElementParser
     */
    private void setApesElementParser(ApplicationContext context) {
        context.getBeansOfType(ApesElementParser.class).forEach((k, v) -> {
            ApesXmlParser.setApesElementParser(v);
        });
    }

    public int getOrder() {
        return 100;
    }
}

